#--*coding:utf-8*--

import os


def handle_upload_file(file, filename,portsystem):
    path = './apidoc/fileapi/'  # 上传文件的保存路径，可以自己指定任意的路径
    if not os.path.exists(path):  # 若该路径不存在，则创建存储文件夹
        os.mkdir(path)
    systemPath = path+portsystem+'/'
    if not os.path.exists(systemPath):
        os.mkdir(systemPath)
    with open(systemPath + filename, 'wb+') as destination:
        for chunk in file.chunks():
            destination.write(chunk)

def build_portSystem_dic(portSystemPath,name):
    if not os.path.exists(portSystemPath):
        os.mkdir(portSystemPath)
        return portSystemPath+'/'+name
    else:
        return portSystemPath+'/'+name


def returnFileContent(filePath):
    # 返回文件信息
    with open(filePath,'rw+') as file:
        content = file.read()
        return content